// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: H Platform Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 54 : TYPE_HPLATFORM

// Function declarations
reserve function HPlatform_DebugDraw
reserve function HPlatform_DebugSpawn

// Static Values

// Tables

function HPlatform_DebugDraw
	DrawSprite(0)
end function


function HPlatform_DebugSpawn
	CreateTempObject(TypeName[H Platform], object.direction, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object.xpos
	object[tempObjectPos].value2 = object.ypos
end function


event ObjectMain
	temp6 = object.xpos
	temp7 = object.ypos
	GetTableValue(temp0, 12, StageSetup_table9)
	GetBit(temp1, object.propertyValue, 0)
	if temp1 == 1
		FlipSign(temp0)
		temp0 += 0x4000
	else
		temp0 -= 0x4000
	end if
	temp0 <<= 8
	object.xpos = object.value1
	object.xpos -= temp0
	if object.value0 == 1
		if object.value3 < 64
			object.value3 += 4
		end if
	else
		if object.value3 > 0
			object.value3 -= 4
		end if
	end if
	temp0 = object.value3
	temp0 <<= 1
	Sin(temp1, temp0)
	temp1 <<= 9
	object.ypos = object.value2
	object.ypos += temp1
	object.value0 = 0
	temp0 = object.xpos
	temp1 = object.ypos
	temp6 &= -0x10000
	temp7 &= -0x10000
	temp4 = object.xpos
	temp4 &= -0x10000
	temp4 -= temp6
	temp5 = object.ypos
	temp5 &= -0x10000
	temp5 -= temp7
	object.xpos = temp6
	object.ypos = temp7
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			object.value0 = 1
			object[currentPlayer].xpos += temp4
			object[currentPlayer].ypos += temp5
		end if
	next
	object.xpos = temp0
	object.ypos = temp1
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -10, 64, 32, 119, 1)
	foreach (TypeName[H Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].xpos
		object[arrayPos0].value2 = object[arrayPos0].ypos
	next
	SetTableValue(TypeName[H Platform], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(HPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(HPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
